<template>
  <div class="times">
    <el-date-picker
      v-model="starTime"
      type="daterange"
      align="right"
      unlink-panels
      range-separator="至"
      start-placeholder="开始日期"
      end-placeholder="结束日期"
      format="yyyy-MM-dd"
      value-format="yyyy-MM-dd"
      :picker-options="pickerOptions"
      size="mini"
    >
    </el-date-picker>
    <!-- format="yyyy-MM-dd HH:mm:ss"
      value-format="yyyy-MM-dd HH:mm:ss" -->
  </div>
</template>
<script>
export default {
  name: "Times",
  data() {
    return {
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
        disabledDate(v) {
          return v.getTime() > Date.now();
        },
      },
      starTime: "",
    };
  },
  watch: {
    starTime(newval) {
      console.log(newval);
      this.$emit("change-time", newval);
      // console.log(this.starTime);
      // console.log(new Date(this.starTime[0]));
    },
  },
};
</script>
<style lang="less" scoped>
.times {
  padding-bottom: 10px;
}
</style>
